package com.lsa.the6046j.ps1;

import java.util.AbstractList;
import java.util.Arrays;
import java.util.List;

public class ReversedListAdapter {
	public static void main(String[] args) {
		List<Integer> l = Arrays.asList(1);
		List<Integer>  rl = new ReversedList<Integer>(l);
		for (Integer e : rl) {
			System.out.println(e);
		}
	}
	
	private static class ReversedList<E> extends AbstractList<E> {
		private final List<E> l;
		
		public ReversedList(List<E> l) {
			this.l = l;
		}

		@Override
		public E get(int i) {
			return l.get(l.size() - 1 - i);
		}

		@Override
		public int size() {
			return l.size();
		}
	}
}
